<?php
if (DATABASE_OK === true) {
	$oUsers = UserHandler::getUsers();
	$oJobgroups = JobgroupHandler::getJobgroups();
	$oJobs = JobHandler::getJobs();
}
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');

require('sajax/Sajax.php');

$sajax_request_type = "GET";
$sajax_debug_mode = false;
sajax_init();
sajax_export('showBox', 'getPiece');
sajax_handle_client_request();

?>
<html>
<head>
<title><?php print cAppName.' '.cAppVersion ?></title>
<link href="css/cool.css" rel="stylesheet">
<link href="css/cool_specific.css" rel="stylesheet">
<link href="css/print.css" rel="stylesheet" media="print">
<link href="css/print_specific.css" rel="stylesheet" media="print">
<?php
// IE-specific *crap*.
if (strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'msie') !== false || true)
{
	?>
	<style type="text/css">
	.hidden {
		position: absolute;
	}
	</style>
	<?php
}
?>
<link href="css/rotmb.css" rel="stylesheet">
<script language="JavaScript" src="js/jquery/jquery-1.7.1.min.js"></script>
<script language="JavaScript" src="js/layers.js"></script>
<script language="JavaScript" src="js/functions.js"></script>
<script language="JavaScript">
	<?php sajax_show_javascript(); ?>
	
	var sViewConductor = new String();
	
	function getPiece_cb(mResult) {
		var mSplitArray = mResult.split('|', 4);
		var sHolder = mSplitArray[2];
		var iOffset = mSplitArray[0].length + mSplitArray[1].length + mSplitArray[2].length + 3;
		var sBody = mResult.substring(iOffset);
		
		document.getElementById(sHolder).innerHTML = sBody;
		elfShow('elf_' + sHolder);
	}
	
	function showBox_cb(mResult) {
		document.getElementById('dialog_holder').innerHTML = mResult;
		sFocusInput = 'focus_' + sViewConductor.replace('-', '_');
		if (document.getElementById(sFocusInput) != null) {
			document.getElementById(sFocusInput).focus();
		}
	}
	
	function getPiece(sView, mArguments, sHolder) {
		x_getPiece(sView, mArguments, sHolder, getPiece_cb);
	}
	
	function togglePiece(sView, mArguments, sHolder) {
		if (document.getElementById(sHolder).innerHTML == '') {
			getPiece(sView, mArguments, sHolder);
		}
		else {
			document.getElementById(sHolder).innerHTML = '';
			elfHide('elf_' + sHolder);
		}
	}
	
	function showBox(sView, mArguments) {
		sViewConductor = sView;
		x_showBox(sView, mArguments, showBox_cb);
	}
	
	function showWindow(sView, mArguments) {
		var url = "index.php?window&sView=" + sView;
		var $window_holder = $("#window_holder");

		if (mArguments != null) {
			for (key in mArguments) {
				url += "&" + key + "=" + escape(mArguments[key]);
			}
		}
		$window_holder.load(
			url,
			null,
			function() {
				var inputs = $window_holder.find(":input[type != 'hidden']");
				if (inputs.length) {
					inputs[0].focus();
				}
				else {
					inputs.focus();
				}
			}
		);
	}
	
</script>
</head>
<body>

<div id="dialog_holder"></div>
<div id="window_holder"></div>

<?php
/*
if ($_SERVER['HTTP_TEST'] == 'Hello') {
	if (!is_int($_SESSION['lognumber'])) {
		$_SESSION['lognumber'] = 0;
	}
	$_SESSION['lognumber']++;
	$oFile = fopen('output.'.$_SESSION['lognumber'].'.txt', 'w+');
	foreach($_SERVER as $h=>$v) {
		if(ereg('HTTP_(.+)', $h, $hp)) {
			echo "$h = $v<br/><br/>";
			fwrite($oFile, $h.' = '.$v."\n\n");
		}
	}

	fwrite($oFile, print_r($_POST, true));

	fclose($oFile);
}
*/
?>

<table cellspacing="0">
	<tr>
<?php
if (!$_SESSION['oUserVars']['hidenav'])
{
	?>
		<td style="vertical-align: top; text-align: center;">
			<table cellspacing="0">
				<tr>
					<td class="frame" nowrap>
						<div class="center small" style="background: transparent;">
						[ <?php print cAppName.' '.cAppVersion ?> ]<br>
	<?php
	if (@$_SESSION['rid'] && is_array($oUsers)) {
		
		?>
						<a href="index.php?sView=user-view&iUser=<?php print $_SESSION['rid'] ?>"><?php print $oUsers[$_SESSION['rid']]->sUser ?></a><br>
						[ <a href="index.php?sVar=images&amp;mValue=16">16</a> |
						<a href="index.php?sVar=images&amp;mValue=24">24</a> ]
						<br>
						[ <a href="index.php?sVar=hidenav&mValue=1"><?php print msg('Hide menu', true) ?></a> ]<br>
		<?php
	}
	?>
						</div>
						<?php showLinks() ?>
					</td>
				</tr>
			</table>
		</td>
	<?php
}
?>
		<td style="vertical-align: top;">
<?php
if (@$_SESSION['rid']) {
	?>
			<table cellspacing="0">
				<tr>
					<td class="frame small">
						<form action="index.php" method="get" name="form_jobchanger">
						<input type="hidden" name="sView" value="job-view">
	<?php
	if ($_SESSION['oUserVars']['hidenav'])
	{
		echo '[ <a href="index.php?sVar=hidenav&mValue=0">'.msg('Show menu', true).'</a> ] ';
	}
	jobSelector('iJobID', $_SESSION['iJobID'], 'if (document.form_jobchanger.iJobID.value != 0) document.form_jobchanger.submit();');
	print ' <input type="button" value="'.msg('Open', true).'" onClick="if (document.form_jobchanger.iJobID.value != 0) document.form_jobchanger.submit();">';
	if (count($oJobs) > 0 && is_object(@$oJobs[$_SESSION['iJobID']])) {
		print ' [ <a href="http://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['REQUEST_URI']).'/index.php?sView=job-view&amp;JobID='.$_SESSION['iJobID'].'">'.msg('Copyable path', true).': '.$oJobs[$_SESSION['iJobID']]->sName.'</a> ] ';
	}
	$sLanguages = AppconfigHandler::getLanguages();
	print ' <select onChange="location.href = \'index.php?sVar=language&mValue=\' + this.value;">';
	foreach ($sLanguages as $sCode => $sLangName) {
		print '<option value="'.$sCode.'" '.($_SESSION['oUserVars']['language'] == $sCode ? 'selected' : '').'>'.$sLangName.'</option>';
	}
	print '</select>';
	?>
						</form>
					</td>
				</tr>
			</table>
	<?php
}
?>
			<div style="padding: 8px 8px 8px 8px;">
<?php
loadBox(@$_REQUEST['sView'] ? $_REQUEST['sView'] : 'job-list');
?>
			</div>
		</td>
	</tr>
</table>
<?php
loadBox('error-list');

if (TRANSLATING_APP === true) {
	loadBox('appconfig-translate', 'sRedirectView='.$_REQUEST['sView']);
}

/* Deprecated 2011-12-26: Should be ported to DataHandler at some point.
if (false) { // For debugging and optimizing SQL queries.
	doQuery();
}
*/
?>
</body>
</html>
